import * as path from "path";
import { startWatchGameConfig } from "./gameConfigMgr";
import { initRedisClient } from "./shared/gameCluster/redisHelper";
import { gameServer, joinGameCluster } from "./server";


async function initServer() {
    await gameServer.autoImplementApi(path.resolve(__dirname, 'api'));
};

async function startServer() {
    await gameServer.start();
    gameServer.logger?.log("游戏服务启动成功!");

    var joinErr = await joinGameCluster();
    if (joinErr) {
        gameServer.logger?.log("加入集群服务器失败:" + joinErr);
    }else{
        gameServer.logger?.log("加入集群服务器成功!");
    }
}

// Entry function
async function main() {
    var gateCfg = startWatchGameConfig();
    initRedisClient(gateCfg.authRedisConfig);

    await initServer();
    await startServer();
}
main();